'''
Created on 11 Oct 2009

@author: joao
'''
import unittest
import lib.primes as primes

class FactorsTests(unittest.TestCase):

	def testFactorsOf1(self):
		factors = primes.factors(1)
		self.assertSequenceEqual([], factors)
	
	def testFactorsOf2(self):
		factors = primes.factors(2)
		self.assertSequenceEqual([2], factors)
		
	def testFactorsOf5(self):
		factors = primes.factors(5)
		self.assertSequenceEqual([5], factors)
		
	def testFactorsOf15(self):
		factors = primes.factors(15)
		self.assertSequenceEqual([3, 5], factors)

	def testFactorsOf100(self):
		factors = primes.factors(100)
		self.assertSequenceEqual([2, 2, 5, 5], factors)

	
	def testFactorsOfHuge(self):
		factors = primes.factors(123456789000)
		self.assertSequenceEqual([2,2,2,3,3,5,5,5,3607,3803], factors)
	
class IsPrimeTests(unittest.TestCase):

	def testIsPrime1(self):
		self.assertTrue(primes.isPrime(1))
		
	def isPrime2(self):
		self.assertTrue(primes.isPrime(2))
	
	def testIsPrime3(self):
		self.assertTrue(primes.isPrime(3))
	
	def testIsPrime4(self):
		self.assertFalse(primes.isPrime(4))
		
	def testIsPrime11(self):
		self.assertTrue(primes.isPrime(11))
		
	def testIsPrime7103 (self):
		self.assertTrue(primes.isPrime(7103))
		
	def testIsPrime7107(self): 
		self.assertFalse(primes.isPrime(7107))
		
	def testIsPrimeHuge(self):
		self.assertTrue(primes.isPrime(2147483647))
		
class SieveTests(unittest.TestCase):
	def testSieveOf1(self):
		primesList = primes.sieve(1)
		self.assertSequenceEqual([], primesList)
		
	def testSieveOf2(self):
		primesList = primes.sieve(2)
		self.assertSequenceEqual([], primesList)
		
	def testSieveOf3(self):
		primesList = primes.sieve(3)
		self.assertSequenceEqual([2], primesList)
		
	def testSieveOfLarge(self):
		primesList = primes.sieve(3000000)
		self.assertEquals(len(primesList), 216816)
		self.assertIn(663983 , primesList)
		self.assertEquals(primesList[-1] , 2999999)
	
if __name__ == "__main__":
	#import sys;sys.argv = ['', 'Test.testName']
	unittest.main()